package hongcaosp.app.android.user.settings.wallet;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import hongcaosp.app.android.R;
import hongcaosp.app.android.modle.BaseResponse;
import hongcaosp.app.android.user.settings.wallet.iview.AccountBindIView;
import hongcaosp.app.android.user.settings.wallet.presenter.AccountBindPresenter;
import xlj.lib.android.base.component.BaseActivity;
import xlj.lib.android.base.toastcompat.ToastManager;

/**
 * 绑定提现账号
 */
public class AccountBindActivity extends BaseActivity implements AccountBindIView {

    /**
     *
     * @param activity
     * @param type 1-支付宝
     * @param requestCode 2-微信
     */
    public static void launcher(Activity activity, int type,int requestCode) {
        Intent intent = new Intent(activity,AccountBindActivity.class);
        intent.putExtra("type",type);
        activity.startActivityForResult(intent,requestCode);
    }

    private TextView tv_lable;
    private EditText et_content;

    private int type;
    private AccountBindPresenter presenter;

    @Override
    protected void initData(Intent intent) {
        type = intent.getIntExtra("type",-1);
        tv_lable.setText(type == 0 ? "支付宝收款账号" : "微信收款账号");
    }

    @Override
    protected void initView() {
        presenter = new AccountBindPresenter(this);
        findViewById(R.id.back_btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        findViewById(R.id.save).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                presenter.bindingPayType(type,et_content.getText().toString().trim());
            }
        });
        tv_lable = findViewById(R.id.tv_label);
        et_content = findViewById(R.id.et_content);
    }

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_account_bind;
    }

    @Override
    public void cashWithdrawalRst(BaseResponse response) {
        if (response != null && response.getCode() == 0) {
            ToastManager.getInstance().showToast("绑定成功");

            Intent intent = new Intent();
            intent.putExtra("account",et_content.getText().toString().trim());
            setResult(RESULT_OK,intent);

            finish();
            return;
        }
        ToastManager.getInstance().showToast(response == null ? "绑定失败" : response.getMessage());
    }
}
